package synonym;

import java.net.URL;
import java.util.HashSet;

public class SynonymMatcher 
{

	private static SynonymDictionary synonyms;
	
	static
	{
		try
		{
			URL url1 = new URL(new URL("file:"), "./resources/exceptions");
			URL url2 = new URL(new URL("file:"), "./resources/synsets");
			URL url3 = new URL(new URL("file:"), "./resources/relations");
			synonyms = new SynonymDictionary(url1, url2, url3);
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	public static boolean IsSynonym(String word1, String word2)
	{
		if(word1.equals(word2))
			return true;
		HashSet<Integer> syns1 = synonyms.getSynSets(word1);
		HashSet<Integer> syns2 = synonyms.getSynSets(word2);
		syns1.retainAll(syns2);
		return !(syns1.isEmpty());
		
	}
}
